package org.example.framework.MiniApplicationContext;

import org.example.framework.BeanDefinitionLoader.BeanDefinitionLoader;
import org.example.framework.BeanDefinitionMap.BeanDefinitionMap;
import org.example.framework.BeanDefinitionMap.SimpleBeanDefinitionMap;

import java.util.HashMap;
import java.util.Map;

public abstract class AbstractApplicationContext implements ApplicationContext{
    protected final Map<String, Object> singletonObjectMap = new HashMap<>();
    protected BeanDefinitionLoader beanDefinitionLoader;

    protected String configLocation;

    @Override
    public void refresh() throws Exception {
        beanDefinitionLoader.run(configLocation);
        finishBeanInitialization();
    }

    private void finishBeanInitialization() throws Exception {
        BeanDefinitionMap beanDefinitionMap = new SimpleBeanDefinitionMap();
        String[] beanDefinitionNames = beanDefinitionMap.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            getBean(beanDefinitionName);
        }
    }
}

